import Common from '../../common/common.js';
import BaseListItem from '../base/BaseListItem.js';
import TimNet from '../../timnet.js';

//寄生组合式继承
function FriendListItemChecked (data) {
    BaseListItem.call(this,data);
    this.checked = false;
    this.role;
    this.muteUntil;
 }
let prototype = Object.create(BaseListItem.prototype);
prototype.constructor = FriendListItemChecked;
FriendListItemChecked.prototype  = prototype;

//操作数据
FriendListItemChecked.prototype.initHandleData = function () {
    return [
        {label:"input",tag:"checkbox",props:{type:"checkbox",checked:this.checked}}
        ]
}

//各个操作事件
FriendListItemChecked.prototype.bind = function(){
    Common.tool.addHandle(this.element,"click",()=>{this.check()})
}

//选择
FriendListItemChecked.prototype.check = function(){
    this.checked = !this.checked;
    this.element.handle.checkbox.checked = this.checked;
}



//设置数据
FriendListItemChecked.prototype.setData = function(data){
    this.data = data;
    this.setAvatar(Common.tool.getAvatar(data.avatar));
    this.setName(Common.tool.isNull(data.nick)?data.userID:data.nick);
    this.setMsg(data.selfSignature);
}

//设置用户
FriendListItemChecked.prototype.updateDataByUserID = function(userID){
    //如果用户存在
    if(Common.cache.userInfo[userID]){
        this.setData(Common.cache.userInfo[userID]);
     }
    else
    {
        TimNet.getUserProfile([userID],(d)=>{
            if(d && d[0]){
                Common.cache.userInfo[userID] = d[0];
                this.setData(d[0]);
            };
        })
    }

    return this;
}

export default FriendListItemChecked
